package com.tofine.smarthome.util;

import com.tofine.smarthome.model.Device;

/**
 * @author ddMax
 * @since 2016/5/6 13:57.
 */
public class DeviceUtils {

    public static String[] parseContent(String content) {
        String[] result = content.split(";");
        return result;
    }

    public static Device getDeviceFromQRCode(String content) {
        String[] result = parseContent(content);
        try {
            String _id = result[0];
            String imageUrl = result[1];
            String name = result[2];
            String intro = result[3];
            String categoryName = result[4];
            Device device = new Device(
                    _id,
                    imageUrl,
                    name,
                    intro,
                    false,
                    false
            );
            device.setCategory(categoryName);
            return device;
        } catch (ArrayIndexOutOfBoundsException e) {
            return null;
        }
    }
}
